<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>06自定义JS对象</title>
</head>
<body>
<table border="1px">
    <tr>
        <th>商品标题</th>
        <th>商品价格</th>
        <th>商品库存</th>
    </tr>
</table>

<script>

    let productArr = [
        {title:'小米14',price:8000,num:200},
        {title:'华为Mate60',price:8000,num:200},
        {title:'苹果16',price:8000,num:200},
        {title:'魅族',price:8000,num:200},
    ]
        for (let i=0;i<productArr.length;i++){
            let tr = document.createElement('tr');
            let titleTd = document.createElement('td');
            let priceTd = document.createElement('td');
            let numTd = document.createElement('td');
            titleTd.innerHTML = productArr[i].title;
            priceTd.innerHTML = productArr[i].price;
            numTd.innerHTML = productArr[i].num;
            tr.append(titleTd,priceTd,numTd);
            let table = document.querySelector('table');
            table.append(tr);
        }
    add();
    //1.创建一个自带属性与方法的对象
    let p1 = {
        name:'张三',
        age:18,
        say:function (){
            console.log('我是' + this.name + ',今年' + this.age + '岁了')
        }
    };
    console.log(p1);
    p1.say();

    //2.先创建一个空对象,再动态添加其属性与方法
    let  p2 = {};
    p2.name = '李四';
    p2.age = 19;
    p2.say = function (){
        console.log('我是' + this.name + ',今年' + this.age + '岁了')
    };
    console.log(p2);
    p2.say();
</script>
</body>
</html>